﻿namespace ImageProcessing
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    /// <summary>
    /// Handle all the gui events
    /// </summary>
    public class HandleGUIEvents
    {

        private static Color newColor;
        /// <summary>
        /// Creates the rotate tool strip.
        /// </summary>
        /// <param name="tS">The TS.</param>
        public static void CreateRotateToolStrip(ref ToolStrip tS)
        {
            ToolStripTextBox rotateAngle = new ToolStripTextBox();
            tS.Visible = true;
            tS.Items.Clear();
            tS.Items.Add(new ToolStripButton("Rotate Left", Image.FromFile(@"Icons\RotateL.png"), delegate { Main.ImageList[Main.CurrImage].UpdateImage(Transformation.Rotate90Left(Main.ImageList[Main.CurrImage].ImageStructArray)); }));

            tS.Items.Add(new ToolStripButton("Rotate Right", Image.FromFile(@"Icons\RotateR.png"), delegate { Main.ImageList[Main.CurrImage].UpdateImage(Transformation.Rotate90Right(Main.ImageList[Main.CurrImage].ImageStructArray)); }));

            tS.Items.Add(rotateAngle);
            tS.Items.Add(new ToolStripLabel(" Rotate", null, true, delegate { Main.ImageList[Main.CurrImage].UpdateImage(Transformation.Rotate(Main.ImageList[Main.CurrImage].ImageStructArray, double.Parse(rotateAngle.Text), Main.ImageList[Main.CurrImage].Width, Main.ImageList[Main.CurrImage].Height, Main.ImageList[Main.CurrImage].VideoProcessing)); }));
            tS.Items.Add(new ToolStripSeparator());

            tS.Items.Add(new ToolStripButton("Flip Vertically", Image.FromFile(@"Icons\FlipV.png"), delegate { Main.ImageList[Main.CurrImage].UpdateImage(Operations.Mirror(Main.ImageList[Main.CurrImage].ImageStructArray, true)); }));

            tS.Items.Add(new ToolStripButton("Flip Horizontly", Image.FromFile(@"Icons\FlipH.png"), delegate { Main.ImageList[Main.CurrImage].UpdateImage(Operations.Mirror(Main.ImageList[Main.CurrImage].ImageStructArray, false)); }));
        }

        /// <summary>
        /// Creates the shear tool strip.
        /// </summary>
        /// <param name="tS">The TS.</param>
        public static void CreateShearToolStrip(ref ToolStrip tS)
        {
            ToolStripTextBox txtTool_ShearOnX = new ToolStripTextBox();
            ToolStripTextBox txtTool_ShearOnY = new ToolStripTextBox();
            tS.Visible = true;
            tS.Items.Clear();
            tS.Items.Add(new ToolStripButton("Shear On X by :", null, delegate { Main.ImageList[Main.CurrImage].UpdateImage(Transformation.ShearOnX(Main.ImageList[Main.CurrImage].ImageStructArray, double.Parse(txtTool_ShearOnX.Text))); }, "Shear On X"));

            tS.Items.Add(txtTool_ShearOnX);
            tS.Items.Add(new ToolStripSeparator());

            tS.Items.Add(new ToolStripButton("Shear On Y by :", null, delegate { Main.ImageList[Main.CurrImage].UpdateImage(Transformation.ShearOnY(Main.ImageList[Main.CurrImage].ImageStructArray, double.Parse(txtTool_ShearOnY.Text))); }, "Shear On Y"));
            tS.Items.Add(txtTool_ShearOnY);
        }

        /// <summary>
        /// Creates the translate tool strip.
        /// </summary>
        /// <param name="tS">The TS.</param>
        public static void CreateTranslateToolStrip(ref ToolStrip tS)
        {
            ToolStripTextBox txtTool_TranslateOnX = new ToolStripTextBox();
            ToolStripTextBox txtTool_TranslateOnY = new ToolStripTextBox();
            tS.Visible = true;
            tS.Items.Clear();

            tS.Items.Add(new ToolStripButton("Translate On X by :", null, delegate { Main.ImageList[Main.CurrImage].UpdateImage(Transformation.Translate(Main.ImageList[Main.CurrImage].ImageStructArray, 0, int.Parse(txtTool_TranslateOnX.Text))); }, "Translate On X"));

            tS.Items.Add(txtTool_TranslateOnX);
            tS.Items.Add(new ToolStripSeparator());

            tS.Items.Add(new ToolStripButton("Translate On Y by :", null, delegate { Main.ImageList[Main.CurrImage].UpdateImage(Transformation.Translate(Main.ImageList[Main.CurrImage].ImageStructArray, int.Parse(txtTool_TranslateOnY.Text), 0)); }, "Translate On Y"));

            tS.Items.Add(txtTool_TranslateOnY);
            tS.Items.Add(new ToolStripSeparator());

            tS.Items.Add(new ToolStripButton("Translate On X and Y", null, delegate { Main.ImageList[Main.CurrImage].UpdateImage(Transformation.Translate(Main.ImageList[Main.CurrImage].ImageStructArray, int.Parse(txtTool_TranslateOnY.Text), int.Parse(txtTool_TranslateOnX.Text))); }, "Translate On X and Y"));
        }

        /// <summary>
        /// Creates the crop tool strip.
        /// </summary>
        /// <param name="tS">The TS.</param>
        public static void CreateCropToolStrip(ref ToolStrip tS)
        {
            tS.Visible = true;
            tS.Items.Clear();
            tS.Items.Add(new ToolStripButton("Done Cropping", null, delegate { Operations.Crop(Main.ImageList[Main.CurrImage].ImageStructArray, ImageEvents.topLeft, ImageEvents.downRight); }));
        }

        /// <summary>
        /// Creates the crop tool strip.
        /// </summary>
        /// <param name="tS">The TS.</param>
        public static void CreateDrawToolStrip(ref ToolStrip tS)
        {
            tS.Visible = true;
            int l = tS.Location.Y+tS.Height;
            tS.Items.Clear();
            ToolStripTextBox txtSize = new ToolStripTextBox();
            ToolStripButton sizeBtn = new ToolStripButton("Size", null, delegate { Main.ImageList[Main.CurrImage].MyShaps.ScaleShapeAction(txtSize.Text); });
            sizeBtn.Width = 100;
            tS.Items.Add(sizeBtn);
            tS.Items.Add(txtSize);
            tS.Items.Add(new ToolStripSeparator());
            tS.Items.Add(new ToolStripButton("Color", null, delegate { changeColor(); }));
            ToolStripButton clrBtn = new ToolStripButton(null, null, delegate { changeColor(); });
            clrBtn.BackColor = newColor;
            clrBtn.BackColor = Color.White;
            tS.Items.Add(clrBtn);
            tS.Items.Add(new ToolStripSeparator());
            Image img = Properties.Resources.Delete;
            tS.Items.Add(new ToolStripButton(null, img, delegate { DeleteShape(); }));
        }

        private static void changeColor()
        {
            newColor =  Main.Instance.ShowColorsForm();
            Main.ImageList[Main.CurrImage].MyShaps.ChangeColorToolStripMenuItemAction(newColor);
            // Invalidate();
        }

        private static void DeleteShape()
        {
            if (Main.ImageList[Main.CurrImage].MyShaps.SelectedShape == null)
            {
                MessageBox.Show("please select shape");
                return;
            }
            Main.ImageList[Main.CurrImage].MyShaps.AllShapes.Remove(Main.ImageList[Main.CurrImage].MyShaps.SelectedShape);
         
        }

        public static void CreateZoomToolStrip(ref ToolStrip tS)
        {
            tS.Visible = true;
            tS.Items.Clear();
            tS.Items.Add(new ToolStripLabel("Percentage"));
            ToolStripComboBox combo = new ToolStripComboBox();
            combo.Items.Add("10%");
            combo.Items.Add("25%");
            combo.Items.Add("50%");
            combo.Items.Add("100%");
            combo.Items.Add("150%");
            combo.Items.Add("200%");
            combo.Items.Add("300%");
            combo.Items.Add("400%");
            combo.Items.Add("500%");
            combo.Text = "100%";
            combo.SelectedIndexChanged+=new EventHandler(combo_SelectedIndexChanged);
            tS.Items.Add(combo);
            tS.Items.Add(new ToolStripSeparator());
            tS.Items.Add(new ToolStripButton(null, Image.FromFile(@"Icons\ZoomIn.png"), Main.Instance.zoomInToolStripMenuItem_Click));
            tS.Items.Add(new ToolStripButton(null, Image.FromFile(@"Icons\ZoomOut-.png"), Main.Instance.zoomOutToolStripMenuItem_Click));
            tS.Items.Add(new ToolStripSeparator());
            tS.Items.Add(new ToolStripButton("100%", null, Main.Instance.toolStripMenuItem10_Click));
        }

        private static void combo_SelectedIndexChanged(object sender, EventArgs e)
        {
            ImageEvents.factorZoom = int.Parse(((ToolStripComboBox)sender).SelectedItem.ToString().Remove(((ToolStripComboBox)sender).SelectedItem.ToString().Length - 1)) / 100F;
            ((PictureBox)Main.Instance.MainTabContainer.tempPanel.Controls[0]).Image = ImageEvents.PictureBoxZoomWH(Main.ImageList[Main.CurrImage].ImageBitmap);

        }

        /// <summary>
        /// Creates the crop tool strip.
        /// </summary>
        /// <param name="tS">The TS.</param>
        public static void CreateVedioToolStrip(ref ToolStrip tS)
        {
            tS.Visible = true;
            tS.Items.Clear();
            ToolStripLabel vedioLabl = new ToolStripLabel("It's a video ..  ");
            vedioLabl.ForeColor = Color.White;
            tS.Items.Add(vedioLabl);
            tS.Items.Add(new ToolStripSeparator());
            tS.Items.Add(new ToolStripButton(null, Image.FromFile(@"Icons\Play.png"), Main.Instance.Play_Click, "Play"));
            tS.Items.Add(new ToolStripButton(null, Image.FromFile(@"Icons\Pause.png"), Main.Instance.Pause_Click, "Pause"));
            tS.Items.Add(new ToolStripSeparator());
            ToolStripButton captureBtn = new ToolStripButton("Capture a frame", null, Main.Instance.Capture_Click);
            captureBtn.ForeColor = Color.White;
            tS.Items.Add(captureBtn);
            tS.Items.Add(new ToolStripSeparator());
            tS.Items.Add(new ToolStripButton(null, Image.FromFile(@"Icons\SpeedUp.png"), Main.Instance.SpeedUP_Click, "Speed Up"));
            tS.Items.Add(new ToolStripButton(null, Image.FromFile(@"Icons\SpeedDown.png"), Main.Instance.SpeedDown_Click, "Speed Down"));
        }
    }
}
